home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / daemons / ipServer / RCS / sockMisc.c,v < prev    next >
Encoding:
Text File  |  1989-03-23  |  10.4 KB  |  508 lines

  1. head     1.3;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.3
  10. date     89.03.23.09.56.10;  author brent;  state Exp;
  11. branches ;
  12. next     1.2;
  13.  
  14. 1.2
  15. date     88.08.16.11.17.42;  author mendel;  state Exp;
  16. branches ;
  17. next     1.1;
  18.  
  19. 1.1
  20. date     88.04.27.08.52.06;  author brent;  state Exp;
  21. branches ;
  22. next     ;
  23.  
  24.  
  25. desc
  26. @Miscellany
  27. @
  28.  
  29.  
  30. 1.3
  31. log
  32. @Remoted stdio.h include
  33. @
  34. text
  35. @/* 
  36.  * sockMisc.c --
  37.  *
  38.  *    Miscellaneous routines to test and socket state information.
  39.  *
  40.  * Copyright 1987 Regents of the University of California
  41.  * All rights reserved.
  42.  * Permission to use, copy, modify, and distribute this
  43.  * software and its documentation for any purpose and without
  44.  * fee is hereby granted, provided that the above copyright
  45.  * notice appear in all copies.  The University of California
  46.  * makes no representations about the suitability of this
  47.  * software for any purpose.  It is provided "as is" without
  48.  * express or implied warranty.
  49.  */
  50.  
  51. #ifndef lint
  52. static char rcsid[] = "$Header: sockMisc.c,v 1.2 88/08/16 11:17:42 mendel Exp $ SPRITE (Berkeley)";
  53. #endif not lint
  54.  
  55.  
  56. #include "sprite.h"
  57. #include "dev/net.h"
  58. #include "ipServer.h"
  59. #include "socket.h"
  60. #include "sockInt.h"
  61.  
  62.  
  63.  
  64. /*
  65.  *----------------------------------------------------------------------
  66.  *
  67.  * Sock_SetError --
  68.  *
  69.  *    Saves the error status in the socket and notifies the client
  70.  *    so it can find out about the error. This routine is used when
  71.  *    the exact socket is known, unlike Sock_ReturnError.
  72.  *
  73.  * Results:
  74.  *    None.
  75.  *
  76.  * Side effects:
  77.  *    The socket state is updated. The client is woken up.
  78.  *
  79.  *----------------------------------------------------------------------
  80.  */
  81.  
  82. void
  83. Sock_SetError(sockPtr, status)
  84.     Sock_SharedInfo    *sockPtr;    /* Sock to be notified. */
  85.     ReturnStatus    status;        /* Error to be saved. */
  86. {
  87.     sockPtr->error = status;
  88.     Sock_NotifyWaiter(sockPtr, FS_READABLE|FS_WRITABLE|FS_EXCEPTION);
  89. }
  90.  
  91.  
  92. /*
  93.  *----------------------------------------------------------------------
  94.  *
  95.  * Sock_IsOptionSet --
  96.  *
  97.  *    Tests the state of the option for a socket.
  98.  *
  99.  * Results:
  100.  *    TRUE        - the option is set.
  101.  *    FALSE        - the option is not set.
  102.  *
  103.  * Side effects:
  104.  *    None.
  105.  *
  106.  *----------------------------------------------------------------------
  107.  */
  108.  
  109. Boolean
  110. Sock_IsOptionSet(sockPtr, option)
  111.     Sock_SharedInfo    *sockPtr;    /* Sock of interest. */
  112.     int        option;
  113. {
  114.     return(sockPtr->options & option);
  115. }
  116.  
  117.  
  118. /*
  119.  *----------------------------------------------------------------------
  120.  *
  121.  * Sock_HasUsers --
  122.  *
  123.  *    Checks if the socket is being used by at least 1 client.
  124.  *
  125.  * Results:
  126.  *    TRUE    - The socket has clients.
  127.  *    FALSE    - No clients are using the socket.
  128.  *
  129.  * Side effects:
  130.  *    None.
  131.  *
  132.  *----------------------------------------------------------------------
  133.  */
  134.  
  135. Boolean
  136. Sock_HasUsers(sockPtr)
  137.     Sock_SharedInfo *        sockPtr;    /* Sock of interest. */
  138. {
  139.     return(sockPtr->clientCount > 0);
  140. }
  141.  
  142.  
  143. /*
  144.  *----------------------------------------------------------------------
  145.  *
  146.  * Sock_Connected --
  147.  *
  148.  *    Changes the socket state to CONNECTED and notifies
  149.  *    the client that this change has occurred.  Called from 
  150.  *    protocol-related routines.
  151.  *
  152.  * Results:
  153.  *    None.
  154.  *
  155.  * Side effects:
  156.  *    The client is woken up.
  157.  *
  158.  *----------------------------------------------------------------------
  159.  */
  160.  
  161. void
  162. Sock_Connected(sockPtr)
  163.     Sock_SharedInfo *        sockPtr;    /* Sock of interest. */
  164. {
  165.     sockPtr->state = CONNECTED;
  166.     if (sockPtr->parentPtr != (Sock_SharedInfo *) NULL) {
  167.     /*
  168.      * SockPtr is a newly-created connection but is not fully
  169.      * initialized. Notify the parent socket so it can complete
  170.      * the initialization.
  171.      */
  172.     Sock_NotifyWaiter(sockPtr->parentPtr, FS_READABLE|FS_WRITABLE);
  173.  
  174.     /*
  175.      * Set the justEstablished flag after Sock_NofityWaiter because that
  176.      * routine indirectly resets it.
  177.      */
  178.     sockPtr->parentPtr->justEstablished = TRUE;
  179.     Sock_NotifyWaiter(sockPtr, FS_READABLE|FS_WRITABLE);
  180.     Sock_NotifyWaiter(sockPtr, FS_READABLE|FS_WRITABLE);
  181.     } else {
  182.     Sock_NotifyWaiter(sockPtr, FS_READABLE|FS_WRITABLE);
  183.     sockPtr->justEstablished = TRUE;
  184.     Sock_NotifyWaiter(sockPtr, FS_READABLE|FS_WRITABLE);
  185.     Sock_NotifyWaiter(sockPtr, FS_READABLE|FS_WRITABLE);
  186.     }
  187. }
  188.  
  189.  
  190. /*
  191.  *----------------------------------------------------------------------
  192.  *
  193.  * Sock_Disconnected --
  194.  *
  195.  *    Changes the socket state to DISCONNECTED and sets flags
  196.  *    so that further I/O on the socket is prevented. The client
  197.  *    is notified of the change. Called from protocol-related routines
  198.  *    when the connection is completely closed.
  199.  *
  200.  * Results:
  201.  *    None.
  202.  *
  203.  * Side effects:
  204.  *    The socket state is updated. The client is woken up.
  205.  *
  206.  *----------------------------------------------------------------------
  207.  */
  208.  
  209. void
  210. Sock_Disconnected(sockPtr)
  211.     Sock_SharedInfo *        sockPtr;    /* Sock_ of interest. */
  212. {
  213.     sockPtr->state = DISCONNECTED;
  214.     sockPtr->flags |= (SOCK_STOP_RECV|SOCK_STOP_SEND);
  215.     Sock_NotifyWaiter(sockPtr, FS_READABLE|FS_WRITABLE);
  216. }
  217.  
  218.  
  219. /*
  220.  *----------------------------------------------------------------------
  221.  *
  222.  * Sock_Disconnecting --
  223.  *
  224.  *    Changes the socket state to DISCONNECTING and sets flags
  225.  *    so that further I/O on the socket is prevented. Called from 
  226.  *    protocol-related routines that need to close down a connection 
  227.  *    in several steps.
  228.  *
  229.  * Results:
  230.  *    None.
  231.  *
  232.  * Side effects:
  233.  *    The socket state is updated.
  234.  *
  235.  *----------------------------------------------------------------------
  236.  */
  237.  
  238. void
  239. Sock_Disconnecting(sockPtr)
  240.     Sock_SharedInfo *        sockPtr;    /* Sock of interest. */
  241. {
  242.     sockPtr->state = DISCONNECTING;
  243.     sockPtr->flags |= (SOCK_STOP_RECV|SOCK_STOP_SEND);
  244. }
  245.  
  246. /*
  247.  *----------------------------------------------------------------------
  248.  *
  249.  * Sock_IsRecvStopped --
  250.  *
  251.  *    Returns the state of the STOP_RECV flag.
  252.  *
  253.  * Results:
  254.  *    TRUE    - no more data will be received from the network.
  255.  *    FALSE    - data can be received.
  256.  *
  257.  * Side effects:
  258.  *    None.
  259.  *
  260.  *----------------------------------------------------------------------
  261.  */
  262.  
  263. Boolean
  264. Sock_IsRecvStopped(sockPtr)
  265.     Sock_SharedInfo *        sockPtr;    /* Sock of interest. */
  266. {
  267.     return(sockPtr->flags & SOCK_STOP_RECV);
  268. }
  269.  
  270. /*
  271.  *----------------------------------------------------------------------
  272.  *
  273.  * Sock_IsSendStopped --
  274.  *
  275.  *    Returns the state of the STOP_SEND flag.
  276.  *
  277.  * Results:
  278.  *    TRUE    - no more data can be sent.
  279.  *    FALSE    - data can be sent.
  280.  *
  281.  * Side effects:
  282.  *    None.
  283.  *
  284.  *----------------------------------------------------------------------
  285.  */
  286.  
  287. Boolean
  288. Sock_IsSendStopped(sockPtr)
  289.     Sock_SharedInfo *        sockPtr;    /* Sock of interest. */
  290. {
  291.     return(sockPtr->flags & SOCK_STOP_SEND);
  292. }
  293.  
  294. /*
  295.  *----------------------------------------------------------------------
  296.  *
  297.  * Sock_StopRecv --
  298.  *
  299.  *    Sets a flag to indicate that further reception of data from
  300.  *    the network has been stopped.
  301.  *
  302.  * Results:
  303.  *    None.
  304.  *
  305.  * Side effects:
  306.  *    The socket state is updated.
  307.  *
  308.  *----------------------------------------------------------------------
  309.  */
  310.  
  311. void
  312. Sock_StopRecv(sockPtr)
  313.     Sock_SharedInfo *        sockPtr;    /* Sock_ of interest. */
  314. {
  315.     sockPtr->flags |= SOCK_STOP_RECV;
  316. }
  317.  
  318. /*
  319.  *----------------------------------------------------------------------
  320.  *
  321.  * Sock_StopSending --
  322.  *
  323.  *    Sets a flag to indicate that further sending of data to
  324.  *    the network has been stopped.
  325.  *
  326.  * Results:
  327.  *    None.
  328.  *
  329.  * Side effects:
  330.  *    The socket state is updated.
  331.  *
  332.  *----------------------------------------------------------------------
  333.  */
  334.  
  335. void
  336. Sock_StopSending(sockPtr)
  337.     Sock_SharedInfo *        sockPtr;    /* Sock_ of interest. */
  338. {
  339.     sockPtr->flags |= SOCK_STOP_SEND;
  340. }
  341.  
  342. /*
  343.  *----------------------------------------------------------------------
  344.  *
  345.  * Sock_UrgentDataNext --
  346.  *
  347.  *    Sets a flag to indicate that urgent data is logically at the
  348.  *    front of the receive buffer.
  349.  *
  350.  * Results:
  351.  *    None.
  352.  *
  353.  * Side effects:
  354.  *    The socket flags are updated.
  355.  *
  356.  *----------------------------------------------------------------------
  357.  */
  358.  
  359. void
  360. Sock_UrgentDataNext(sockPtr)
  361.     Sock_SharedInfo *        sockPtr;    /* Sock_S of interest. */
  362. {
  363.     sockPtr->flags |= SOCK_URGENT_DATA_NEXT;
  364. }
  365.  
  366.  
  367. /*
  368.  *----------------------------------------------------------------------
  369.  *
  370.  * Sock_HaveUrgentData --
  371.  *
  372.  *    Notifies the client and controlling process or family that
  373.  *    urgent data has arrived.
  374.  *
  375.  * Results:
  376.  *    None.
  377.  *
  378.  * Side effects:
  379.  *    A signal may be sent to the controlling process or family.
  380.  *    Any users waiting for urgent data are woken up.
  381.  *
  382.  *----------------------------------------------------------------------
  383.  */
  384.  
  385. void
  386. Sock_HaveUrgentData(sockPtr)
  387.     Sock_SharedInfo *        sockPtr;    /* Sock_ of interest. */
  388. {
  389.     /*
  390.      * The owner PID is non-zero, then signal the owner process or family
  391.      * that there's urgent data.
  392.      */
  393.     Sock_NotifyWaiter(sockPtr, FS_EXCEPTION);
  394.     if (sockPtr->owner.id != 0) {
  395.     if (ips_Debug) {
  396.         (void) fprintf(stderr, 
  397.         "Sock_HaveUrgentData: sending URGENT signal to %x (%s)\n",
  398.         sockPtr->owner.id, 
  399.         sockPtr->owner.procOrFamily == IOC_OWNER_FAMILY ? 
  400.             "family" : "process");
  401.     }
  402.  
  403.     Sig_Send(SIG_URGENT, sockPtr->owner.id, 
  404.             sockPtr->owner.procOrFamily == IOC_OWNER_FAMILY);
  405.     }
  406. }
  407.  
  408.  
  409. /*
  410.  *----------------------------------------------------------------------
  411.  *
  412.  * Sock_BadRoute --
  413.  *
  414.  *    Called when a protocol-dependent routine has determined
  415.  *    that a route is bad.
  416.  *
  417.  *    Just a stub procedure for now.
  418.  *
  419.  * Results:
  420.  *    None.
  421.  *
  422.  * Side effects:
  423.  *    None.
  424.  *
  425.  *----------------------------------------------------------------------
  426.  */
  427.  
  428. /*ARGSUSED*/
  429. void
  430. Sock_BadRoute(sockPtr)
  431.     Sock_SharedInfo     *sockPtr;    /* Socket with the bad route. */
  432. {
  433. }
  434. @
  435.  
  436.  
  437. 1.2
  438. log
  439. @
  440. @
  441. text
  442. @d18 1
  443. a18 1
  444. static char rcsid[] = "$Header: sockMisc.c,v 1.1 88/04/27 08:52:06 brent Exp $ SPRITE (Berkeley)";
  445. a26 2
  446.  
  447. #include <stdio.h>
  448. @
  449.  
  450.  
  451. 1.1
  452. log
  453. @Initial revision
  454. @
  455. text
  456. @d18 1
  457. a18 1
  458. static char rcsid[] = "$Header: sockMisc.c,v 6.0 87/09/08 15:58:58 andrew Stable $ SPRITE (Berkeley)";
  459. d28 1
  460. a28 2
  461. #include "fs.h"
  462. #include "io.h"
  463. a29 1
  464.  
  465. d52 1
  466. a52 1
  467.     Sock_SharedInfo    *sockPtr;    /* Socket to be notified. */
  468. d79 1
  469. a79 1
  470.     Sock_SharedInfo    *sockPtr;
  471. d105 1
  472. a105 1
  473.     Sock_SharedInfo    *sockPtr;
  474. d131 1
  475. a131 1
  476.     Sock_SharedInfo    *sockPtr;
  477. d179 1
  478. a179 1
  479.     Sock_SharedInfo    *sockPtr;
  480. d208 1
  481. a208 1
  482.     Sock_SharedInfo    *sockPtr;
  483. d233 1
  484. a233 1
  485.     Sock_SharedInfo *sockPtr;
  486. d257 1
  487. a257 1
  488.     Sock_SharedInfo *sockPtr;
  489. d281 1
  490. a281 1
  491.     Sock_SharedInfo *sockPtr;
  492. d305 1
  493. a305 1
  494.     Sock_SharedInfo *sockPtr;
  495. d329 1
  496. a329 1
  497.     Sock_SharedInfo *sockPtr;
  498. d355 1
  499. a355 1
  500.     Sock_SharedInfo    *sockPtr;
  501. d364 1
  502. a364 1
  503.         Io_PrintStream(io_StdErr, 
  504. d399 1
  505. a399 1
  506.     Sock_SharedInfo    *sockPtr;    /* Socket with the bad route. */
  507. @
  508.